package collection;

import java.util.*;

public class SotrString {
    public static void main(String[] args) {
        /*
        List<String> list = new ArrayList<>();
        list.add("jack");
        list.add("rose");
        list.add("tom");
        list.add("jack");
        list.add("alice");
        System.out.println("list原始数据："+list);
        //对英文字符串排序时，会按字母的ASCII码来排
        Collections.sort(list);
        System.out.println("list排序后："+list);

         */
        List<String> list = new ArrayList<>();
        list.add("张宛婷啦啦啦+");
        list.add("张大大大");
        list.add("张小小小小");
        System.out.println("原始集合："+list);
        Collections.sort(list, new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();//升序
                //return  o2.length()-o1.length();//降序
            }
        });
        Collections.sort(list,(o1,o2)-> o1.length() - o2.length());
        System.out.println("排序后为：" + list);

    }

}

